#ifndef _IMPL_H_
#define _IMPL_H_

#ifdef windows
#include <stdint.h>
typedef uint8_t u8;
#endif

#ifdef linux
#include <stdint.h>
typedef uint8_t u8;
#endif


enum evTypes {
  E_LE,
  E_DTR,
  E_RTS,
  E_ST,
  E_SR,
  E_CTS,
  E_CAR,
  E_RNG,
  E_DSR,
  E_RX,
  E_TX,
  E_FRAME,
  E_OVERRUN,
  E_PARITY,
  E_BRK,
  E_BUFOVERRUN,
  E_IOIN,
  E_IOOUT,
  E_IOERR,
  E_IOHUP,
  E_NUM_EVENTS
};

#define E_CD E_CAR
#define E_RI E_RNG


typedef struct
{
    int state[E_NUM_EVENTS];
    int occ[E_NUM_EVENTS];
} EvInfos;

typedef struct
{ 
    char portName[128];

    void *data;
} CommInfo;

char *findPorts();
CommInfo *openPort(char *portName);
int setBlock(CommInfo *ci);
int setNonblock(CommInfo *ci);
int enableDTR(CommInfo *ci);
int disableDTR(CommInfo *ci);
int enableRTS(CommInfo *ci);
int disableRTS(CommInfo *ci);
int getCTS(CommInfo *ci);
int getDSR(CommInfo *ci);
int getRI(CommInfo *ci);
int getCD(CommInfo *ci);
int setParityNone(CommInfo *ci);
int setParityOdd(CommInfo *ci);
int setParityEven(CommInfo *ci);
int setStopBits1(CommInfo *ci);
int setStopBits2(CommInfo *ci);
int setDataBits5(CommInfo *ci);
int setDataBits6(CommInfo *ci);
int setDataBits7(CommInfo *ci);
int setDataBits8(CommInfo *ci);
int setFlowNone(CommInfo *ci);
int setFlowHW(CommInfo *ci);
int setFlowSW(CommInfo *ci);
int setBaud(CommInfo *ci, int baud);
int flush(CommInfo *ci);
int closePort(CommInfo *ci);
int readPort(CommInfo *ci, u8 *buf, int len);
int writePort(CommInfo *ci, u8 *buf, int len);
int available(CommInfo *ci);
void beginEvents(CommInfo *ci);
int pollEvents(CommInfo *ci, EvInfos *infos);
int waitEvents(CommInfo *ci, EvInfos *infos);
int waitErrorEvents(CommInfo *ci, EvInfos *infos);
int waitLineEvents(CommInfo *ci, EvInfos *infos);

#endif
